package com.yl.test;

import cn.hutool.core.collection.ListUtil;
import com.yl.util.JdkUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.state.StateTtlConfig;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;

import java.util.List;

/**
 * @author wlf
 * @since 2022/8/9
 */
@Slf4j
public class IntegrityExample {

    public static void main(String[] args) throws Exception {
        JdkUtil.disableWarning();
        // 流环境
        Configuration configuration = new Configuration();
//        configuration.setString("execution.savepoint.path", "file:///tmp/flinkcdc/86ed67953d0e36364b79d433605d1603/chk-3");
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
        // 设置保存点
        env.enableCheckpointing(3000);
        // 设置本地保存（如果是windows默认盘为当前项目所在的盘）
        env.getCheckpointConfig().setCheckpointStorage("file:///ttmp/flinkcdc/");

        // socket 数据源
        DataStreamSource<String> streamSource = env.socketTextStream("elephant", 6666);

        streamSource
                .keyBy((KeySelector<String, String>) s -> s.split(" ")[0])
                .flatMap(new CustomFunc())
                .print();

        System.out.println("### 流配置完毕 ###");
        // 懒加载
        env.execute();
    }
}
